﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../css/themes/default/jquery.mobile-1.4.2.min.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery.js" type="text/javascript"></script>
    <script src="../js/jquery.mobile-1.4.2.js" type="text/javascript"></script>
</head>
<body>
    <div data-role="header" data-position="fixed" data-theme="a">
        <a href="../" data-rel="back" class="ui-btn ui-btn-left ui-alt-icon ui-nodisc-icon ui-corner-all ui-btn-icon-notext ui-icon-carat-l">
            Back</a>
        <h1>
            设置</h1>
    </div>
    <div data-role="page" data-title="注册" class="jqm-demos">
        <input type="text" name="username" id="username" placeholder="帐号" data-clear-btn="true" />
        <input type="password" name="password" id="password" placeholder="密码" data-clear-btn="true" />
        <div>
            <a data-role="button" id="btnReg" data-theme="b">注册</a>
            <script type="text/javascript">
                $("#btnReg").click(function () {
                    var username = document.getElementById("username").value;
                    if (username == null || username == "") {
                        alert("请输入用户名！");
                        return;
                    }
                    var db = window.openDatabase("SugarDB", "1.0", "SugarDB", 5000000);
                    db.transaction(queryDB, errorCB, successCB);
                });
                //插入数据
                function queryDB(tx) {
                    var username = document.getElementById("username").value;
                    var password = document.getElementById("password").value;
                    var selectsql = "select * from UserAccount where username='" + username + "'";
                    tx.executeSql(selectsql, [], querySuccess, errorCB);


                }
                // 查询成功后调用的回调函数
                function querySuccess(tx, results) {
                    var username = document.getElementById("username").value;
                    var password = document.getElementById("password").value;
                    if (results.rows.length != 0) {
                        alert("已经存在用户: " + username);
                    }
                    else {
                        var InsertDataTableUserSql = "insert into  UserAccount (userid,username,password) values(?,?,?)";
                        tx.executeSql(InsertDataTableUserSql, [0, username, password]);
                        alert("注册成功！");
                    }
                }
                function errorCB(err) {
                    console.log("错误处理的SQL：" + err.code + "错误信息：" + err.message);
                    alert("错误信息：" + err.message);

                }
                // 事务执行成功后调用的回调函数
                function successCB() {

                }
            </script>
        </div>
    </div>
</body>
</html>
